<extend name="Public/base"/>

<block name="body">
    <div class="main-title cf">
        <h2>奖品设置</h2>
    </div>
    <!-- 表单 -->
    <form id="form" action="{:U('update')}" method="post" class="form-horizontal">
        <!-- 基础文档模型 -->
        <div id="tab1" class="tab-pane in tab1">
            <div class="form-item cf">
                <label class="item-label">期数<span class="check-tips"></span></label>
                <div class="controls">
                    第<input type="text" class="text input-large" name="periods" value="{$periods}" style="width:120px;text-align:center;" readonly>期
                </div>
            </div>
            <div class="form-item cf">
                <label class="item-label btn1"><span class="check-tips"><input type="button" value="新增奖项" class="btn" /></span></label>
                <notempty name="info">
                    <volist name="info" id="vo">
                        <div class="controls">
                            奖项： <input type="text" class="text input-large" name="prize_name[]" value="{$vo.prize_name}" style="width:120px;">
                            金额： <input type="text" class="text input-large" name="prize_money[]" value="{$vo.prize_money}" style="width:120px;">
                            数量： <input type="text" class="text input-large" name="prize_num[]" value="{$vo.prize_num}" style="width:60px;">
                            规则： <input type="text" class="text input-large" name="prize_rule[]" value="{$vo.prize_rule}" style="width:120px;">
                            <if condition="$i neq 1"><input type="button" class="cancl btn" value="删除"/></if>
                        </div>
                    </volist>
                 <else/>
                    <div class="controls">
                        奖项： <input type="text" class="text input-large" name="prize_name[]" value="{$info.unique}" style="width:120px;">
                        金额： <input type="text" class="text input-large" name="prize_money[]" value="{$info.unique}" style="width:120px;">
                        数量： <input type="text" class="text input-large" name="prize_num[]" value="{$info.unique}" style="width:60px;">
                        规则： <input type="text" class="text input-large" name="prize_rule[]" value="{$info.unique}" style="width:120px;">
                    </div>
                </notempty>
            </div>
            <!--<div class="form-item cf">-->
                <!--<label class="item-label">banner图片</label>-->
                <!--<div class="controls">-->
                    <!--<input type="file" id="upload_picture">-->
                    <!--<input type="hidden" id="cover_id" name="cover_id" value="{$info.cover_id}"/>-->
                    <!--<div class="upload-img-box">-->
                        <!--<notempty name="info['cover_id']">-->
                            <!--<div class="upload-pre-item"><img src="{$info.cover_id|get_cover='path'}"/></div>-->
                        <!--</notempty>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->

        </div>
        <!--<input type="hidden" name="id" value="{$info.id}"/>-->
        <div class="form-item cf">
            <input class="btn submit-btn hidden" type="submit" value="确 定" />
            <input class="btn btn-return" type="reset" value="重置" />
        </div>
    </form>
</block>
<block name="script">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">

        (function(){
            var url = "{$current}";
            $("#subnav").find("a[href='" + url + "']").parent().addClass("current");

            //上传文件
            /* 初始化上传插件 */
            $("#download-file").uploadify({
                "height"          : 30,
                "swf"             : "__STATIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传文件",
                "uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
                "width"           : 120,
                'removeTimeout'   : 1,
                "onUploadSuccess" : uploadSuccess
            });

            /* 文件上传成功回调函数 */
            function uploadSuccess(file, data){
                var data = $.parseJSON(data);
                if(data.status){
                    $("input[name=file]").val(data.data);
                    $("input[name=file]").parent().find('.upload-img-box').html(
                            "<div class=\"uplaod-pre-file\">" + data.info + "</div>"
                    );
                } else {
                    updateAlert(data.info);
                }
            }

            //上传图片
            /* 初始化上传插件 */
            $("#upload_picture").uploadify({
                "height"          : 230,
                "swf"             : "__STATIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传图片",
                "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                // "width"           : 120,
                'removeTimeout'	  : 1,
                'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                "onUploadSuccess" : uploadPicture
            });
            function uploadPicture(file, data){
                var data = $.parseJSON(data);
                if(data.status){
                    $("#cover_id").val(data.id);
                    $("#cover_id").parent().find('.upload-img-box').html(
                            '<div class="upload-pre-item"><img src="' + data.path + '"/></div>'
                    );
                } else {
                    updateAlert(data.info);
                }
            }

        })();
        $(".btn1").click(function(){
            var html='<div class="controls">';
            html+=' 奖项： <input type="text" class="text input-large" name=prize_name[]" value="" style="width:120px;">';
            html+=' 金额： <input type="text" class="text input-large" name="prize_money[]" value="" style="width:120px;">';
            html+=' 数量： <input type="text" class="text input-large" name="prize_num[]" value="" style="width:60px;">';
            html+=' 规则： <input type="text" class="text input-large" name="prize_rule[]" value="" style="width:120px;"><input type="button" class="cancl btn" value="删除"/></div>';
            $(this).parent(".form-item").append(html);
        })
        $(".btn1").parent().on('click','.cancl',function(){
           $(this).parent().remove();
        })
        var aa='{"id":"370","path":"\/Uploads\/Picture\/2016-01-12\/569457ea09d7b.png","url":"","md5":"beb0814405335b03186f24ca99f325eb","sha1":"037581cb376a22f8d998d112c968052893d59761","status":1,"create_time":"1452562409","info":"\u4e0a\u4f20\u6210\u529f","data":""}';
        var data = $.parseJSON(aa);
    </script>
</block>

